package cn.itcast.service.impl;

import cn.itcast.dao.PermissionDao;
import cn.itcast.entity.PageResult;
import cn.itcast.entity.QueryPageBean;
import cn.itcast.entity.Result;
import cn.itcast.pojo.Permission;
import cn.itcast.service.PermissionService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao;
    //权限分页查询
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        //基于mybatis分页查询插件进行分页查询
        PageHelper.startPage(currentPage,pageSize);
        Page<Permission> page = permissionDao.findByCondition(queryString);

        return new PageResult(page.getTotal(),page.getResult());
    }

    //添加权限
    public void add(Permission permission) {
        permissionDao.add(permission);
    }

    //修改权限
    public void editById(Permission permission) {
        permissionDao.editById(permission);
    }

    //删除权限
    public void delete(Integer id) {
        permissionDao.delete(id);
    }
}
